// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {},
    imgList: [],
    menuList: [],
    xh:{
      name: "xh",
      age: 18
    }
  },
  
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  truePage() {
    let item = JSON.stringify(this.data.xh)
    console.log(item)
    wx.navigateTo({
      url: '../turnPage/turnPage?xh=' + item
    })
  },

  // 获取轮播图
  getImg(){
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
      success: (val)=>{
        // console.log(val.data.message)
        this.setData({
          imgList: val.data.message
        })
        // console.log(this.data.imgList)
      }
    })
  },

  // 获取导航栏
  getMenu(){
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/catitems',
      success:(val)=>{
        var listD = val.data.message
        var iconList = ['apps-o','shopping-cart-o','shop-o','shop-collect-o']
        listD.forEach((item,index) => {
          item.path = "/pages/listInfo/listInfo",
          item.icon = iconList[index]
        });
        this.setData({
          menuList: listD
        })
        // console.log(this.data.menuList)
      }
    })
  },

  // 单击事件
  handleInfo(e){
    // console.log(e)
    wx.navigateTo({
      url: '/pages/listInfo/listInfo'
    })
  },

  onLoad() {
    this.getImg()
    this.getMenu()
  },
  
  
})
